package com.myjunjie.blog.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.myjunjie.blog.entity.Article;
import com.myjunjie.blog.service.IArticleService;
import com.myjunjie.blog.service.impl.ArticleServiceImpl;
import com.myjunjie.blog.util.StringHelper;

public class UpdateArticleServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");

		String id = request.getParameter("id");
		String title = request.getParameter("title"); // 获取到文章标题
		String category = request.getParameter("category");// 获取文章类别
		String mdtxt = request.getParameter("mdtxt");// 获取markdown格式

		// 创建对象
		Article article = new Article();
		article.setId(id);
		article.setTitle(title);
		article.setMdtxt(mdtxt);
		article.setCategory(category);
		article.setPublish_time(StringHelper.getCurrentTimeStamp());

		// 调用服务
		IArticleService articleService = new ArticleServiceImpl();
		boolean isSuccess = articleService.upateArticle(article);

		// 返回结果
		PrintWriter out = response.getWriter();
		out.println(isSuccess);

	}

}
